#include "keypad.h"
#include "headfile.h"

void keypad_Init(void)
{
    gpio_init(P00_0 | P00_1 | P00_2 | P00_3 | P00_4 | P00_5 | P00_6 | P00_7, GPO, 0, PUSHPULL);
}

void keypad16(void)
{
    gpio_set(P00_0 | P00_1 | P00_2 | P00_3, 1);
    gpio_set(P00_4 | P00_5 | P00_6 | P00_7, 0);
}

void keypad16_De(void)
{
    gpio_set(P00_0 | P00_1 | P00_2 | P00_3, 0);
    gpio_set(P00_4 | P00_5 | P00_6 | P00_7, 1);
}

void scan(void)
{
    uint32 temp1, temp2;
    uint value;

    keypad16();
    temp1 = IfxPort_getGroupState(&MODULE_P00, 0, 0xff);
    systick_delay_ms(STM0, 5);

    keypad16_De();
    temp2 = IfxPort_getGroupState(&MODULE_P00, 0, 0xff);
    systick_delay_ms(STM0, 5);

    temp1 = temp1 | temp2;

    switch(temp1)
    {
        case 0xe7:
        {
            value = 1;
        }break;

        case 0xd7:
        {
            value = 2;
        }break;

        case 0xb7:
        {
            value = 3;
        }break;

        case 0x77:
        {
            value = 4;
        }break;

        case 0xeb:
        {
            value = 5;
        }break;

        case 0xdb:
        {
            value = 6;
        }break;

        case 0xbb:
        {
            value = 7;
        }break;

        case 0x7b:
        {
            value = 8;
        }break;

        case 0xed:
        {
            value = 9;
        }break;

        case 0xdd:
        {
            value = 10;
        }break;

        case 0xbd:
        {
            value = 11;
        }break;

        case 0x7d:
        {
            value = 12;
        }break;

        case 0xee:
        {
            value = 13;
        }break;

        case 0xde:
        {
            value = 14;
        }break;

        case 0xbe:
        {
            value = 15;
        }break;

        case 0x7e:
        {
            value = 16;
        }break;
    }
}




